import React, { useState } from 'react';

import { demoUtil } from '../../utils';

import {
  ResourceManager,
  columnFieldsMap,
  ResourceManagerProps,
} from 'easyComponent';

import { commonData } from './commonData';

export default () => {
  const [pagination, setPagination] = useState({
    total: 100,
    pageSize: 10,
    current: 1,
  });
  const config: ResourceManagerProps = {
    componentsMap: columnFieldsMap,
    rowKey: 'id',
    title: '用户管理',
    pagination,
    features: {
      pagination: { showQuickJumper: true, showTotal: true },
    },
    fields: [
      {
        label: '姓名',
        name: 'name',
        componentName: 'TextColumnField',
      },
      {
        label: '描述',
        name: 'desc',
        componentName: 'TextColumnField',
        width: '200px',
        ellipsis: true,
      },
      {
        label: '链接',
        name: 'linkName',
        linkKey: 'url',
        componentName: 'LinkColumnField',
      },
      {
        label: '操作',
        name: 'name',
        componentName: 'OperationColumnField',
        actions: [
          {
            label: '编辑',
            handler: () => {
              demoUtil.toastInfo('你点击了编辑');
            },
          },
        ],
      },
    ],
  };

  return (
    <div>
      <ResourceManager
        {...config}
        dataSource={commonData.simpleDataSource}
        onChange={(event, args) => {
          setPagination(args.pagination as any);
          console.log(event, args);
        }}
      />
    </div>
  );
};
